package com.csy.admin.service.impl;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csy.admin.entity.LearningExperience;
import com.csy.admin.mapper.LearningExperienceMapper;
import com.csy.admin.service.LearningExperienceService;
import com.csy.admin.util.PageUtils;
import com.csy.admin.util.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  学习经验实现类
 * </p>
 *
 * @author csy
 * @since 2018-09-19
 */
@Service
public class LearningExperienceServiceImpl extends ServiceImpl<LearningExperienceMapper, LearningExperience> implements LearningExperienceService {

    @Autowired
    private LearningExperienceMapper learningExperienceMapper;


    /**
     * 多条件查询经验列表
     * @param params
     */
    @Override
    public PageUtils queryExperienceList(Map<String,Object> params) {
        String title = (String) params.get("title");
        String classIdStr = (String) params.get("classId");
        String tagIdStr = (String) params.get("tagId");
        Integer classId = -1;
        Long tagId = -1L;
        if(StringUtils.isNotBlank(classIdStr)){
            classId = Integer.parseInt(classIdStr);
        }
        if(StringUtils.isNotBlank(tagIdStr)){
            tagId = Long.parseLong(tagIdStr);
        }
        IPage<LearningExperience> page = learningExperienceMapper.selectExperienceList(
                new Query<LearningExperience>(params).getPage(), title,classId,tagId);
        List<LearningExperience> experienceList = page.getRecords();
        page.setRecords(experienceList);
        return new PageUtils(page);
    }
}
